//
//  WHPersonageViewController.m
//  WHstoreItemProtect
//
//  Created by wztx on 2017/11/4.
//  Copyright © 2017年 sdwh.com. All rights reserved.
//

#import "WHPersonageViewController.h"

#import "UIColor+Addition.h"

#import "LWGroupItem.h"
#import "LWSettingItem.h"

#import "WHYueViewController.h"
#import "WHlifeFees.h"
#import "WHlocationViewController.h"

@interface WHPersonageViewController ()

//当前界面的数据源 用来存储分组模型
@property (nonatomic ,strong) NSMutableArray *groupArray;

@end

@implementation WHPersonageViewController

#pragma MARK - 懒加载
- (NSMutableArray *)groupArray
{
    if (!_groupArray) {
        _groupArray = [NSMutableArray array];
    }
    return _groupArray;
}
//构造
- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupNavgationBar];
    [self setupUI];
    
    [self group1];
    [self group2];
    [self group3];
    
    
}

#pragma mark - 导航栏的设置
- (void)setupNavgationBar {
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xFF6800];
    
}
#pragma MARK - UI
- (void)setupUI
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 140)];
    headerView.backgroundColor = [UIColor magentaColor];
    
    self.tableView.tableHeaderView = headerView;
    
}
#pragma MARK - 条目分组
- (void)group1
{
    LWGroupItem *group0 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"余额" icon:@"yue"];
    LWSettingItem *item1 = [LWSettingItem itemWithTitle:@"我的积分" icon:@"jifen"];
    LWSettingItem *item2 = [LWSettingItem itemWithTitle:@"生活缴费" icon:@"jiaofei"];
    
    group0.itemsArray = @[item,item1,item2];
    
    [self.groupArray addObject:group0];
    
}
- (void)group2
{
    LWGroupItem *group1 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"金融理财" icon:@"licai"];
    LWSettingItem *item1 = [LWSettingItem itemWithTitle:@"账单" icon:@"zhangdan"];
    LWSettingItem *item2 = [LWSettingItem itemWithTitle:@"金融产品订单" icon:@"dingdan"];
    group1.itemsArray = @[item,item1,item2];
    [self.groupArray addObject:group1];
}
- (void)group3
{
    LWGroupItem *group4 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"我的评价" icon:@"pingjia"];
    LWSettingItem *item1 = [LWSettingItem itemWithTitle:@"我的地址" icon:@"address"];
    LWSettingItem *item3 = [LWSettingItem itemWithTitle:@"商家入驻" icon:@"ruzhu"];
    group4.itemsArray = @[item1,item,item3];
    [self.groupArray addObject:group4];
    
}
/**
 *  返回有多少组的代理方法
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.groupArray.count;
}

/**
 *  返回每组有多少行的代理方法
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    LWGroupItem *group = self.groupArray[section];
    return group.itemsArray.count;
}

/**
 *  返回每一行Cell的代理方法
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    LWGroupItem *group = self.groupArray[indexPath.section];
    LWSettingItem *item = group.itemsArray[indexPath.row];
    cell.textLabel.text = item.title;
    cell.imageView.image = [UIImage imageNamed:item.icon];
    return cell;
}
/**
 *  选中每一行Cell的代理方法
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                NSLog(@"余额");
            {
                WHYueViewController  *yueVc = [[WHYueViewController alloc]init];
                yueVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:yueVc animated:YES];
            }
                break;
            case 1:
                NSLog(@"积分");
                break;
            case 2:
                NSLog(@"缴费");
            {
                WHlifeFees *feeVc = [WHlifeFees new];
                feeVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:feeVc animated:YES];
            }
                
                default:
                break;
        }
        
    }else if (indexPath.section == 1)
    {
        switch (indexPath.row) {
            case 0:
                NSLog(@"理财");
                break;
            case 1:
                NSLog(@"账单");
                break;
            case 2:
                NSLog(@"金融订单");
                
                
            default:
                break;
        }
    }else if (indexPath.section == 2)
    {
        switch (indexPath.row) {
            case 0:
                NSLog(@"地址");
            {
                WHlocationViewController *locationVc = [WHlocationViewController new];
                locationVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:locationVc animated:YES];
            }
                break;
            case 1:
                NSLog(@"评价");
                break;
            case 2:
                NSLog(@"商家");
                
            default:
                break;
        }
    }
}




@end
